package com.finance.logistics.anlyzier;


import com.finance.base.constant.BaseConstants;
import com.finance.report.bean.pojo.LogisticsData;
import com.finance.report.bean.pojo.LogisticsErrorLog;
import com.finance.report.service.ILogisticsErrorLogService;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;


/**
 * 根据解析错误类型解析
 * Created by gyw on 2017/6/5
 */
@Component
public class ChooseByTypeHandler{
    @Autowired
    protected ILogisticsErrorLogService logisticsErrorLogService;

    @Resource
    private DirectionHandler directionHandler;

    @Resource
    private TemperatureHandler temperatureHandler;

    @Resource
    private ImportsourceHandler importsourceHandler;

    @Resource
    private SupplierHandler supplierHandler;

    @Resource
    private PostmanHandler postmanHandler;

    @Resource
    private DeliverySiteHandler deliverySiteHandler;

    @Resource
    private AcceptOrganizationHandler acceptOrganizationHandler;

    @Resource
    private StatusHandler statusHandler;

    @Resource
    private ConsigneeAddressHandler consigneeAddressHandler;


    public void getErrorType(){
        List<LogisticsErrorLog> logisticsErrorLogList = logisticsErrorLogService.getByMonth(new Date());
        if(logisticsErrorLogList != null && logisticsErrorLogList.size() >0){
            for(LogisticsErrorLog logisticsErrorLog : logisticsErrorLogList){
                LogisticsData logisticsData = (LogisticsData) JSONObject.toBean(JSONObject.fromObject(logisticsErrorLog.getRequestLogInfo()),LogisticsData.class);
                switch (logisticsErrorLog.getErrorType()){
                    case BaseConstants.ANALYZE_ERROR_TYPE_DIRECZTION :
                        directionHandler.doHandler(logisticsData);
                        break;
                    case BaseConstants.ANALYZE_ERROR_TYPE_TEMPERATURE:
                        temperatureHandler.doHandler(logisticsData);
                        break;
                    case BaseConstants.ANALYZE_ERROR_TYPE_IMPORTSOURCE:
                        importsourceHandler.doHandler(logisticsData);
                        break;
                    case BaseConstants.ANALYZE_ERROR_TYPE_SUPPLIER:
                        supplierHandler.doHandler(logisticsData);
                        break;
                    case BaseConstants.ANALYZE_ERROR_TYPE_POSTMAN:
                        postmanHandler.doHandler(logisticsData);
                        break;
                    case BaseConstants.ANALYZE_ERROR_TYPE_DELIVERYSITE:
                        deliverySiteHandler.doHandler(logisticsData);
                        break;
                    case BaseConstants.ANALYZE_ERROR_TYPE_ACCEPTORGANIZATION:
                        acceptOrganizationHandler.doHandler(logisticsData);
                        break;
                    case BaseConstants.ANALYZE_ERROR_TYPE_STATUS:
                        statusHandler.doHandler(logisticsData);
                        break;
                    case BaseConstants.ANALYZE_ERROR_TYPE_CONSIGNEEADDRESS:
                        consigneeAddressHandler.doHandler(logisticsData);
                        break;
                    default:
                        break;
                }
            }
        }
    }
}
